package com.ruoyi.business;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class StockServer {

    public static void main(String[] args) throws IOException {
        int PORT = 8000;  // 请确保与Python客户端中的端口一致

        try (ServerSocket serverSocket = new ServerSocket(PORT)) {
            System.out.println("Java server listening on port " + PORT);

            while (true) {
                Socket clientSocket = serverSocket.accept();
                System.out.println("Connected to Python client");

                try (BufferedReader in = new BufferedReader(
                        new InputStreamReader(clientSocket.getInputStream(), StandardCharsets.UTF_8))) {

                    String dataFromPython = in.readLine();
                    System.out.println("Received data from Python: " + dataFromPython);
                    // 处理接收到的数据...


                } catch (IOException e) {
                    System.err.println("Error reading data from Python client: " + e.getMessage());
                }
                clientSocket.close();
                System.out.println("Disconnected from Python client");
            }
        }
    }
}
